﻿using System.ServiceModel.Channels;
using System.ServiceModel;
using System.Xml;

namespace AAA.Base.Util.WCF
{
	public class WCFUtil
	{
		private const int MAX_RECEIVE_MESSAGE_SIZE = 6553500;
		public static Binding CreateBinding(string strProtrocal)
		{
			Binding binding = null;
			switch (strProtrocal)
            {
#if !SILVERLIGHT
				case "net.tcp":
					NetTcpBinding tcpbinding = new NetTcpBinding();
					tcpbinding.Security.Mode = SecurityMode.None;
					binding = tcpbinding;
					// 單一string 可以 超過 8196 
					XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas();
					quotas.MaxStringContentLength = MAX_RECEIVE_MESSAGE_SIZE;
					tcpbinding.ReaderQuotas = quotas;
					tcpbinding.MaxReceivedMessageSize = MAX_RECEIVE_MESSAGE_SIZE;
					break;
#endif
                case "http":
					BasicHttpBinding httpbinding = new BasicHttpBinding();
					httpbinding.MaxReceivedMessageSize = MAX_RECEIVE_MESSAGE_SIZE;
					httpbinding.MaxBufferSize = MAX_RECEIVE_MESSAGE_SIZE;
					binding = httpbinding;
					break;
			}
			return binding;
		}
	}

}
